package single;

/**
 * @Author longhj
 * @Description 双重锁校验(线程安全)
 * @Date 2021/09/04 星期六 15:03
 */
public class DoubleLockCheckThreadSafety {
    private DoubleLockCheckThreadSafety() {}

    /**
     *  volatile 关键字确保：当uniqueInstance变量被初始化成Singleton实例时，
     *  多个线程正确地处理uniqueInstance变量
     */
    private volatile DoubleLockCheckThreadSafety doubleLockCheckThreadSafety;

    public DoubleLockCheckThreadSafety getDoubleLockCheckThreadSafety() {
        if (null != doubleLockCheckThreadSafety) {
            return doubleLockCheckThreadSafety;
        }
        synchronized (DoubleLockCheckThreadSafety.class) {
            if (null==doubleLockCheckThreadSafety) {
                doubleLockCheckThreadSafety = new DoubleLockCheckThreadSafety();
            }

        }
        return doubleLockCheckThreadSafety;
    }

}
